package com.ms.service.module.zone;

import com.ms.service.error.ErrorCode;
import com.ms.service.module.account.db.AccountDAO;
import com.ms.service.module.account.db.AccountModel;
import com.ms.service.module.zone.message.SOPIDResponse;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.message.MessageAction;
import com.xpec.c4.service.module.task.TaskAsyncCommand;

public class GetAccountOPIDAsync extends TaskAsyncCommand{

	private GUID accountID;
	
	private GUID sessionID;
	
	@Override
	public void asyncExecute() throws Exception {
		SOPIDResponse response = new SOPIDResponse();
		int errorCode;
		
		if(accountID != null && sessionID != null){
			AccountModel accountModel = AccountDAO.loadAccountModelByAccountId(accountID);
			if(accountModel != null){
				response.setOpID(accountModel.getCooperatorAccountId());
				errorCode = ErrorCode.SUCCESS;
			}
			else errorCode = ErrorCode.DB_OPERATION_FAIL;
		}
		else errorCode = ErrorCode.NO_ACCOUNT_DATA;
		
		response.setErrorCode(errorCode);
		MessageAction.sendMessage(sessionID, MessageTypes.S_GET_OP_ID_RESPONSE, response);
	}

	@Override
	public void execute() throws Exception {
		
	}

	public void setAccountID(GUID accountID) {
		this.accountID = accountID;
	}

	public void setSessionID(GUID sessionID) {
		this.sessionID = sessionID;
	}

}
